Page({

data:{
  historyList:[],
  historyList2:[],
  replyfoot:true,
  replyhead:false,
  footstyle:'',
  headstyle:"#fff",
  footweight:'',
  headweight:"1000",
  up_show:false,
  hid:false,
},

gotodetail: function(event){
  wx.navigateTo({
    url: `../detail/detail?historyid=${event.target.dataset.historyid}`,
  });
},

getfoot:function(event){
  this.setData({
    replyfoot:false,
    replyhead:true,
    footstyle:"#fff",
    headstyle:'',
    footweight:"1000",
    headweight:'',
    hid:false,
  });
},

gethead:function(event){
  this.setData({
    replyfoot:true,
    replyhead:false,
    footstyle:'',
    headstyle:"#fff",
    footweight:'',
    headweight:"1000",
  });
},

onLoad: function(options){
  wx.showNavigationBarLoading()
   wx.cloud.callFunction({
     name:'historylist',
     data:{
       start:this.data.historyList.length,
       count:10
     }
   }).then(res=>{
     console.log(res);
     this.setData({
       historyList:this.data.historyList.concat(JSON.parse(res.result).result).reverse(),
       historyList2:this.data.historyList.concat(JSON.parse(res.result).result),
       hid:true,
     });
   }).catch(err=>{
     console.error(err);
   })
   wx.hideNavigationBarLoading({
     complete: (res) => {
       console.log("1");
     },
   })

  console.log('onLoad');
  var that = this;
  var time_m = new Date().getMonth();
  var time_date = new Date().getDate();
  var time_year = new Date().getFullYear();
  var time_month;
  switch ( time_m ) {
    case 0:
      time_month = '一月';
      break;
    case 1:
      time_month = '二月';
      break;
    case 2:
      time_month = '三月';
      break;
    case 3:
      time_month = '四月';
      break;
    case 4:
      time_month = '五月';
      break;
    case 5:     
      time_month = '六月';
      break;
    case 6:     
      time_month = '七月';
      break;
    case 7:     
      time_month = '八月';
      break;
    case 8:     
      time_month = '九月';
      break;
    case 9:     
      time_month = '十月';
      break;
    case 10:     
      time_month = '十一月';
      break;
    case 11:     
      time_month = '十二月';
      break;
    }
  that.setData({
    time_month:time_month,
    time_date:time_date,
    time_year:time_year
  })
},

//监听画面滑动
onPageScroll:function(e){
  var that=this;
  if(e.scrollTop > 50){
    that.setData({
      up_show:true
    })
  }
  if(e.scrollTop < 50){
    that.setData({
      up_show:false
    })
  }
},
//点击置顶
gotop:function(e){
  if(wx.pageScrollTo){
    wx.pageScrollTo({
      scrollTop:0
    })
  }else{
    wx.showModal({
      title:'错误',
      content:'微信版本过低',
    })
  }
},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    return{
      title:'历史上的今天',
      path:'/pages/today/today?tgid=',
      success:function(res){
        wx.showToast({
          title: '分享成功',
        })
      },
      fail:function(res){
        wx.showToast({
          title: '分享失败',
        })
      }
    }

  },

  toshare:function(res){
    return{
      title:'历史上的今天',
      path:'/pages/today/today?tgid=',
      success:function(res){
        wx.showToast({
          title: '分享成功',
        })
      },
      fail:function(res){
        wx.showToast({
          title: '分享失败',
        })
      }
    }
  }


})